Skip to content

Make VLAN reconciles create-only so existing NetBox VLANs are not rewritten - #270

Open
a-courteille wants to merge 1 commit into
emersonfelipesp:mainfrom
a-courteille:fix/vlan-reconcile-create-only
Open

a-courteille wants to merge 1 commit into
emersonfelipesp:mainfrom
a-courteille:fix/vlan-reconcile-create-only

Conversation

@a-courteille

Copy link
Copy Markdown

Summary

Node and VM interface sync reconciles /api/ipam/vlans/ by VID with a hard-coded payload (name: "VLAN <vid>", status: active, Proxbox tags) and no patchable_fields. On a NetBox that already documents its VLANs, the first sync renames every VLAN whose VID appears on an interface to VLAN <vid>, forces it to active, and replaces its tags.

This PR makes VLAN reconciles create-only:

  • A VID that is missing from NetBox is still created as VLAN <vid>, exactly as before.
  • When a VLAN with that VID already exists, the interface is linked to it and the VLAN itself is not patched.

Changes

  • proxmox_to_netbox/models.py: new NETBOX_VLAN_PATCHABLE_FIELDS: frozenset[str] = frozenset(), next to NetBoxVlanSyncState.
  • The constant is passed as patchable_fields to all eight VLAN reconciles:
    • services/sync/network.py: _sync_legacy_node_vlan, _sync_node_interface_vlan, _resolve_vm_interface_vlan and bulk_reconcile_vlans
    • services/sync/vm_network.py
    • services/sync/vm_network_processor.py
    • services/sync/individual/interface_sync.py
    • routes/virtualization/virtual_machines/sync_vm.py
  • tests/test_vlan_reconcile_create_only.py:
    • behavioural tests through the real rest_reconcile_async: an existing VLAN (DEV_COMMON, status reserved) is linked with no save() and no POST, and a missing VID is created as VLAN <vid>;
    • a static AST guard: every rest_reconcile_async / rest_bulk_reconcile_async call on /api/ipam/vlans/ must pass NETBOX_VLAN_PATCHABLE_FIELDS. On main it reports all 8 call sites; on this branch it reports none.
  • docs/sync/workflows.md and docs/pt-BR/sync/workflows.md: a paragraph documenting the create-only VLAN behaviour.

Not changed:

  • The sdn.py lookup is read-only.
  • When one VID exists in several sites or groups, the first match is still the one linked. That could be a separate change.

Validation

  • Real sync, before vs after, on a copy of a production NetBox (NetBox 4.7.4, netbox-proxbox 0.0.29.post6, PVE 9.1.7, 3-node cluster, 140 pre-existing VLANs). The "after" run used the official 0.0.27.post4 image with an equivalent create-only filter applied in netbox_rest.py:

    Without fix With fix
    Existing VLANs modified 36 0 (compared field by field: name, status, site, group, tenant, description, tags)
    New VLANs created 31 31
    Node interfaces linked to their VLAN yes yes, to the existing VLANs

    The sync job completed successfully.

…ritten

Node and VM interface sync reconciled /api/ipam/vlans/ by VID with a
hard-coded payload (name "VLAN <vid>", status active, Proxbox tags) and no
patchable_fields. Every pre-existing VLAN whose VID appeared on an interface
was therefore renamed, forced to active and re-tagged on the first sync.

Pass NETBOX_VLAN_PATCHABLE_FIELDS (an empty set) to all eight VLAN
reconciles: missing VLANs are still created as "VLAN <vid>", existing ones
are only linked. A static test guards future VLAN call sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant